<html>
<head>
	<meta charset="UTF-8">
	<meta content="IE=edge" http-equiv="X-UA-Compatible">
	<meta content="initial-scale=1.0, maximum-scale=1.0, user-scalable=no, width=device-width" name="viewport">
	<title>2479：[Wc1999]迷宫改造</title>
	<!-- css -->
	<link href="../css/base.min.css" rel="stylesheet">
	<link href="../css/project.min.css" rel="stylesheet">
	
	<!-- favicon -->
	<!-- ... -->
</head>
<body class="page-brand">
	<header class="header header-transparent header-waterfall ui-header">
		<ul class="nav nav-list pull-left">
			<li>
				<a data-toggle="menu" href="#menu">
					<span class="icon icon-lg">menu</span>
				</a>
			</li>
		</ul>
		<a class="header-logo header-affix-hide margin-left-no margin-right-no" data-offset-top="213" data-spy="affix">[Wc1999]迷宫改造</a>
		<span class="header-logo header-affix margin-left-no margin-right-no" data-offset-top="213" data-spy="affix">[Wc1999]迷宫改造</span>
	</header>
	<nav aria-hidden="true" class="menu" id="menu" tabindex="-1">
		<div class="menu-scroll">
			<div class="menu-content">
				<a class="menu-logo" href="../index.html">BZOJ离线题库</a>
				<ul class="nav">
					<li>
						<a class="waves-attach" data-toggle="collapse" href="#problems">题目</a>
						<ul class="menu-collapse collapse in" id="problems">
							<li>
								<a class="waves-attach" href="../index.html">主页</a>
							</li>
							<li>
								<a class="waves-attach" href="../list.html">题目列表</a>
							</li>
						</ul>
					</li>
					<li>
						<a class="collapsed waves-attach" data-toggle="collapse" href="#about">关于</a>
						<ul class="menu-collapse collapse" id="about">
							<li>
								<a class="waves-attach" href="../about.html">关于此项目</a>
							</li>
						</ul>
					</li>
					
				</ul>
			</div>
		</div>
	</nav>
	<main class="content">
		<div class="content-header ui-content-header">
			<div class="container">
				<h1 class="content-heading">
                [Wc1999]迷宫改造                </h1>
                <p>时间限制：10s&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  空间限制：128MB</p>			</div>
		</div>
		<div class="container">
			<section class="content-inner margin-top-no">
				<div class="row">
					<div class="col-lg-13 col-md-13">
						<div class="card margin-bottom-no">
							<div class="card-main">
								<div class="card-inner">
									
                                <h3>题目描述</h3><p><div style="text-indent: 21pt">XX娱乐公司最近获得了一些古希腊迷宫的拥有权，为了使这些古典式迷宫能够吸引更多的游客，<span>XX公司计划对这些迷宫进行合理的改造。你的任务是根据所给的一个迷宫，针对公司的设计要求，在原有迷宫的基础上设计出一个最佳的新式迷宫。</span></div>
<div style="text-indent: 21pt">迷宫的外形是一个长方形，其在南北方向被划分为<span>N行，在东南方向被划分为M列，于是整个迷宫被划分为N&times;M个单元。我们用一个有序数对（单元的行号，单元的列号）来表示单元位置。南北或东西方向相邻的两个单元之间存在一堵墙或者一扇门，墙是不可逾越的，而门是双向的且可以任意通过。出于保护文物的目的，XX公司决定只适当地将墙改置为门，而不进行其它改造，并且要求新迷宫是最佳的，即新置的门的总数要最少。</span></div>
<div style="text-indent: 21pt">公司计划推出一个面向家庭的迷宫游戏。</div>
<div style="text-indent: 21pt"><span style="color: blue">游戏规则如下</span>：</div>
<div style="text-indent: 21pt">假定有<span>P（1&lt;=P&lt;=3）个家庭成员，他们分别从P个指定的起点出发，要求他们只能向南或向东移动，分别到达P个指定的终点。</span></div>
<div style="text-indent: 21pt">公司需要你针对上述游戏规则，设计一个最佳的迷宫，使得这样的游戏是可行的，即所有的家庭成员可以从各自的起点出发依照游戏规则到达各自的终点。</div></p><hr/><h3>输入格式</h3><p><p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-indent: 21pt"><span style="font-family: 宋体; mso-bidi-font-size: 10.5pt"><font size="3">输入文件中的第一行为两个整数<span lang="EN-US">N</span>，<span lang="EN-US">M</span>（<span lang="EN-US">3&lt;=N</span>，<span lang="EN-US">M&lt;=20</span>）。<span lang="EN-US"><o:p></o:p></span></font></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-indent: 21pt"><span style="font-family: 宋体; mso-bidi-font-size: 10.5pt"><font size="3">第二行中为一个整数<span lang="EN-US">k</span>，表示原迷宫中门的总个数。<span lang="EN-US"><o:p></o:p></span></font></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-indent: 21pt"><span style="font-family: 宋体; mso-bidi-font-size: 10.5pt"><font size="3">第<span lang="EN-US">i+2</span>（<span lang="EN-US">1&lt;=i&lt;=k</span>）行中为四个整数<span lang="EN-US">X<sub>i</sub>1</span>，<span lang="EN-US">Y<sub>i</sub>1</span>，<span lang="EN-US">X<sub>i</sub>2</span>，<span lang="EN-US">Y<sub>i</sub>2</span>，表示第<span lang="EN-US">X<sub>i</sub>1</span>行第<span lang="EN-US">Y<sub>i</sub>1</span>列的单元与第<span lang="EN-US">X<sub>i</sub>2</span>行<span lang="EN-US">Y<sub>i</sub>2</span>列的单元之间有一扇门，其中：<span lang="EN-US">|X<sub>i</sub>1-Y<sub>i</sub>1|+|X<sub>i</sub>2-Y<sub>i</sub>2|=1</span>。<span lang="EN-US"><o:p></o:p></span></font></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-indent: 21pt"><span style="font-family: 宋体; mso-bidi-font-size: 10.5pt"><font size="3">第<span lang="EN-US">k+3</span>行中为一个整数，表示<span lang="EN-US">p</span>的值。<span lang="EN-US"><o:p></o:p></span></font></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-indent: 21pt"><span style="font-family: 宋体; mso-bidi-font-size: 10.5pt"><font size="3">第<span lang="EN-US">k+3+j</span>（<span lang="EN-US">1&lt;=j&lt;=p</span>）行中为四个整数<span lang="EN-US">X<sub>j</sub>1</span>，<span lang="EN-US">Y<sub>j</sub>1</span>，<span lang="EN-US">X<sub>j</sub>2</span>，<span lang="EN-US">Y<sub>j</sub>2</span>，分别表示第<span lang="EN-US">j</span>个家庭成员出发的起点位置（<span lang="EN-US">X<sub>j</sub>1</span>，<span lang="EN-US">Y<sub>j</sub>1</span>）和要到达的终点位置（<span lang="EN-US">X<sub>j</sub>2</span>，<span lang="EN-US">Y<sub>j</sub>2</span>），其中：<span lang="EN-US">X<sub>j</sub>1&lt;=X<sub>j</sub>2</span>，<span lang="EN-US">Y<sub>j</sub>1&lt;=Y<sub>j</sub>2</span>，（<span lang="EN-US">X<sub>j</sub>1</span>，<span lang="EN-US">Y<sub>j</sub>1</span>）<span lang="EN-US">&lt;&gt;</span>（<span lang="EN-US">X<sub>j</sub>2</span>，<span lang="EN-US">Y<sub>j</sub>2</span>）。<span lang="EN-US"><o:p></o:p></span></font></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-indent: 21pt; mso-char-indent-count: 2.0"><font size="3"><span style="color: red; font-family: 宋体; mso-bidi-font-size: 10.5pt">注意</span><span style="font-family: 宋体; mso-bidi-font-size: 10.5pt">：输入数据中同一行各相邻整数之间用一空格分隔。<span lang="EN-US"><o:p></o:p></span></span></font></p>
<p></p></p><hr/><h3>输出格式</h3><p><p><span style="font-size: 10.5pt; font-family: 宋体; mso-font-kerning: 1.0pt; mso-bidi-font-family: 'Times New Roman'; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA">为一个整数，表示你所设计的最佳迷宫中新置的门的个数。</span></p></p><hr/><h3>样例输入</h3><pre>4 4
5
1 1 1 2
2 1 3 1
2 2 3 2
4 2 4 3
1 4 2 4
3
2 1 4 3
1 2 4 2
3 1 4 4
</pre><hr/><h3>样例输出</h3><pre>4</pre><hr/><h3>提示</h3><p>没有写明提示</p><hr/><h3>题目来源</h3><p>没有写明来源</p>
								</div>
							</div>
						</div>
					</div>
				</div>
				
				
			</section>
		</div>
	</main>

	<div class="fbtn-container">
		<div class="fbtn-inner">
			<a class="fbtn fbtn-lg fbtn-brand-accent waves-attach waves-circle waves-light waves-effect" data-toggle="dropdown" aria-expanded="true"><span class="fbtn-text fbtn-text-left">Menu</span><span class="fbtn-ori icon">apps</span><span class="fbtn-sub icon">close</span></a>
			<div class="fbtn-dropup">
				<a class="fbtn fbtn-brand waves-attach waves-circle waves-light waves-effect" href="../list.html" target="_self"><span class="fbtn-text fbtn-text-left">题目列表</span><span class="icon">menu</span></a>
				<a class="fbtn fbtn-green waves-attach waves-circle waves-effect" href="../index.html" target="_self"><span class="fbtn-text fbtn-text-left">返回主页</span><span class="icon">home</span></a>
				<a class="fbtn waves-attach waves-circle waves-effect" href="http://www.lydsy.com/JudgeOnline/submitpage.php?id=2479" target="_blank"><span class="fbtn-text fbtn-text-left">提交代码</span><span class="icon">send</span></a>
				<a class="fbtn fbtn-orange waves-attach waves-circle waves-effect" href="http://www.lydsy.com/JudgeOnline/wttl/wttl.php?pid=2479" target="_blank"><span class="fbtn-text fbtn-text-left">试题讨论</span><span class="icon">chat</span></a>
				
			</div>
		</div>
	</div>

	<!-- js -->
	<script src="../js/jquery.min.js"></script>
	<script src="../js/base.min.js"></script>
	<script src="../js/project.min.js"></script>
</body>
</html>